$(document).ready(function(){

	 $(".date").datepicker({
		 showOn: "button",
		 dateFormat: 'mm/yy',
		 buttonImage: "images/glyphicons_045_calendar.png",
		 buttonImageOnly: true,
		 showButtonPanel: true,
		 changeMonth: true,
		 changeYear: true,
		 onClose: function(dateText, inst) { 
             var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
             var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
             $(this).datepicker('setDate', new Date(year, month, 1));
         },
         beforeShow : function(input, inst) {
//        	 setTimeout(function() {   
//	    		   var buttonPane = $( input )   
//	    		     .datepicker( "widget" )   
//	    		     .find( ".ui-datepicker-buttonpane" );   
//	    		  
//	    		   var btn = $('<BUTTON class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all">Annulla</BUTTON>');   
//	    		   btn.unbind("click").bind("click", function () {   
//		    		   $.datepicker._clearDate( input );
//		    		   $.datepicker._setDate( null ); 
//	    		   });   
//    		  
//    		   btn.appendTo( buttonPane );   
//    		  
//    		 }, 1 );   

             if ((datestr = $(this).val()).length > 0) {
                 year = datestr.substring(datestr.length-4, datestr.length);
                 month = parseInt(datestr.substring(0, datestr.length-5),10)-1;
                 $(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
                 $(this).datepicker('setDate', new Date(year, month, 1));
             }
         }

	 });
});
